package com.xqls.service.impl;

import com.xqls.dal.dao.DrainFlowRecordDao;
import com.xqls.dal.model.DrainFlowRecord;
import com.xqls.service.DrainFlowRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class DrainFlowRecordServiceImpl implements DrainFlowRecordService {
	@Autowired
	private DrainFlowRecordDao flowDao;

	@Override
	public List<Map<String, Object>> selMinRecordByMap(Map<String, Object> map) {
		return flowDao.selectMinByMap(map);
	}

	@Override
	public List<Map<String, Object>> selHourRecordByMap(Map<String, Object> map) {
		return flowDao.selectHourByMap(map);
	}

	@Override
	public List<Map<String, Object>> selDayRecordByMap(Map<String, Object> map) {
		return flowDao.selectDayByMap(map);
	}

	@Override
	public List<Map<String, Object>> selMonthRecordByMap(Map<String, Object> map) {
		return flowDao.selectMonthByMap(map);
	}

	@Override
	public List<Map<String, Object>> selYearRecordByMap(Map<String, Object> map) {
		return flowDao.selectYearByMap(map);
	}

	@Override
	public Map<String, Object> selDayCumulativeFlow(Map<String, Object> map) {
		return flowDao.selDayCumulativeFlow(map);
	}

	@Override
	public boolean save(double cumulative_flow, String enterprise_no, double instantaneous_flow ,Date date) {
		DrainFlowRecord flowRecord = new DrainFlowRecord();
		flowRecord.setCumulativeFlow(cumulative_flow);
		flowRecord.setEnterpriseNo(enterprise_no);
		flowRecord.setInstantaneousFlow(instantaneous_flow);
		flowRecord.setRecordingTime(date);
		int result = flowDao.insert(flowRecord);
		return result > 0;
	}

	@Override
	public boolean insertToMonth(Map<String, Object> map) {
		Map<String, Object> monthMap = flowDao.selectMapFromDayFlow(map);
		int result = 0;
		if (monthMap != null) {
			map.put("recordingTime", monthMap.get("recordingTime"));
			map.put("cumulativeFlow", monthMap.get("cumulativeFlow"));
			result = flowDao.insertToMonth(map);
		}
		return result > 0;
	}

	@Override
	public boolean insertToDay(Map<String, Object> map) {
		Map<String, Object> dayMap = flowDao.selectMapFromFlow(map);
		int result = 0;
		if (dayMap != null) {
			map.put("recordingTime", dayMap.get("recordingTime"));
			map.put("cumulativeFlow", dayMap.get("cumulativeFlow"));
			result = flowDao.insertToDay(map);
		}
		return result > 0;
	}

	@Override
	public Map<String, Object> selectYearColumn(Map<String, Object> map) {
		return flowDao.selectYearColumn(map);
	}

	@Override
	public Map<String, Object> selectLastMaxBeforeThis(Map<String, Object> map) {
		return flowDao.selectMaxBeforeThisByMap(map);
	}

	@Override
	public Map<String, Object> selectMapFromDayFlow(Map<String, Object> map) {
		return flowDao.selectMapFromDayFlow(map);
	}
	@Override
	public List<Map<String, Object>> getMinuteListByMap(Map<String, Object> map) {
		return this.flowDao.getMinuteListByMap(map);
	}

	@Override
	public List<Map<String, Object>> getHourListByMap(Map<String, Object> map) {
		return this.flowDao.getHourListByMap(map);
	}

	@Override
	public List<Map<String, Object>> getDayListByMap(Map<String, Object> map) {
		return this.flowDao.getDayListByMap(map);
	}

	@Override
	public List<Map<String, Object>> getMonthListByMap(Map<String, Object> map) {
		return this.flowDao.getMonthListByMap(map);
	}

	@Override
	public List<Map<String, Object>> getYearListByMap(Map<String, Object> map) {
		return this.flowDao.getYearListByMap(map);
	}
}
